package com.yanqu.road.server.channelserver.cmd.activity.entername;

import com.yanqu.road.entity.activity.entername.UserEnterName;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.cross3.activity.EnterNameProto;
import com.yanqu.road.server.channelserver.cmd.ChannelCommand;
import com.yanqu.road.server.channelserver.logic.ChannelMessageHelper;
import com.yanqu.road.server.channelserver.manager.activity.entername.ChannelEnterNameMgr;
import com.yanqu.road.server.channelserver.manager.activity.entername.EnterNameActivity;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.N_ENTER_NAME_MEMBER_VALUE, desc = "各分组成员贡献")
public class ChannelEnterNameGroupMemberValueCmd extends ChannelCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        EnterNameProto.ChannelEnterNameGroupMemberValueReqMsg reqMsg = EnterNameProto.ChannelEnterNameGroupMemberValueReqMsg.parseFrom(packet.getBytes());
        int activityId = reqMsg.getActivityId();
        long userId = reqMsg.getUserKey().getUserId();
        EnterNameActivity activity = ChannelEnterNameMgr.getEnterNameActivity(activityId);
        UserEnterName userEnterName = ChannelEnterNameMgr.getUserEnterName(activityId, userId);
        if(activity != null && userEnterName != null){
            EnterNameProto.EnterNameGroupMemberListMsg.Builder builder = activity.getGroupMember(reqMsg.getPage(), reqMsg.getPageSize(), reqMsg.getGroupId(), reqMsg.getType());
            EnterNameProto.EnterNameGroupMemberValueRespMsg.Builder clientMsg = EnterNameProto.EnterNameGroupMemberValueRespMsg.newBuilder();
            clientMsg.setRet(0);
            clientMsg.setList(builder);
            ChannelMessageHelper.sendGamePacket(Protocol.U_ENTER_NAME_MEMBER_VALUE, clientMsg, reqMsg.getUserKey().getChannelId(), reqMsg.getUserKey().getServerId(), userId);
        }
    }

    @Override
    public void sendData() {

    }
}
